<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Resize Scroll</title>
    <style>
        #container {
            border: 1px solid #ccc; 
            height: 300px;
            width: 300px;
            overflow: scroll; 
            position: relative;
        }
        #content {
            background-color: #ccc;
            left: 0;
            top: 0;
            width: 200%;
            height: 100%;
            position: absolute;
        }
    </style>
    <script>
        var container_el;
        var content_el;
        document.addEventListener('DOMContentLoaded', function () {   
            var button = document.getElementById('slide');
            content_el = document.getElementById('content');
            container_el = document.getElementById('container');
            button.onclick = function () {
                container_el.scrollLeft = container_el.scrollWidth;
            };
            container_el.onscroll = function(){
                console.log([container_el.scrollLeft, container_el.scrollWidth, container_el.style.offsetWidth]);
            }
            document.getElementById('tobig').onclick = function(){
                container_el.style.width = `${container_el.offsetWidth + 1}px`;
            }
            document.getElementById('tosmall').onclick = function(){
                container_el.style.width = `${container_el.offsetWidth - 5}px`;
            }
        }, false);
    </script>
</head>
<body>
    <div id="container">
        <div id="content">你好.</div>
    </div>
    <button id="slide" type="button">滑动</button>
    <button id="tobig" type="button">容器加大</button>
    <button id="tosmall" type="button">容器变小</button>
</body>
</html>